package com.cheng.im.service.protobuilder;

import com.cheng.im.common.bean.msg.ProtoMsgV1;
import com.cheng.im.service.util.SnowflakeIdWorker;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MessageGroupBuilder {

    @Resource
    SnowflakeIdWorker snowflakeIdWorker;

    public ProtoMsgV1.Message updateSeqAndMsgId(ProtoMsgV1.Message sourceMsg, long seq) {
        ProtoMsgV1.Message.Builder builder = sourceMsg.toBuilder();
        builder.setSequence(seq);

        ProtoMsgV1.MessageGroupRequest.Builder msgBuilder = sourceMsg.getMessageGroupRequest().toBuilder();
        msgBuilder.setMsgId(snowflakeIdWorker.nextId());

        builder.setMessageGroupRequest(msgBuilder);

        return builder.build();
    }
}
